package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.PermissionDao;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import sun.security.acl.PermissionImpl;

import java.util.ArrayList;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
@Autowired
private PermissionDao permissionDao;
    @Override
    public List<String> findKeywordByUsername(String username) {
        List<String> keyword=new ArrayList<>();
      int userId=permissionDao.findIdByUsername(username);
      int roleId=permissionDao.findRoleIdByUserId(userId);
      String roleKeyword=permissionDao.findRoleKeywordByRoleId(roleId);
      keyword.add(roleKeyword);
      List<Integer> permissionIds=permissionDao.findPermissionIdsByRoleId(roleId);
      for(Integer permissionId:permissionIds){
          String permissionKeyword=permissionDao.findPermissionKeyWordByPermissionId(permissionId);
          keyword.add(permissionKeyword);
      }
        return keyword;
    }
}
